Demonstrates how easily can WebControls.GridView be populated with data read from OPC Data Access server.
The default page code-behind:
// $Header: $ // Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved. // ReSharper disable ArrangeModifiersOrder // ReSharper disable InconsistentNaming // ReSharper disable UnusedAutoPropertyAccessor.Local // DataGridWebApplication: Demonstrates how easily can GridView be populated with data read from OPC Data Access server. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . using System; using System.Collections.Generic; using OpcLabs.BaseLib.OperationModel; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.DataAccess.Extensions; namespace DataGridWebApplication { public partial class _Default : System.Web.UI.Page { class Row { public string ItemId { get; set; } public string Value { get; set; } } static _Default() { // Enable auto-subscribing optimization (not necessary), which can improve performance with repeated Read requests. Client.TryEnableAutoSubscribingOptimization(); } // Use a shared client instance to allow for better optimization. static private readonly EasyDAClient Client = new EasyDAClient(); protected void Page_Load(object sender, EventArgs e) { var itemDescriptors = new DAItemDescriptor[] { "Simulation.Register_BOOL", "Simulation.Register_I2", "Demo.Ramp", "Demo.Single" }; ValueResult[] valueResults = Client.ReadMultipleItemValues("OPCLabs.KitServer.2", itemDescriptors); var data = new List<Row>(); for (int i = 0; i < itemDescriptors.Length; i++) data.Add(new Row { ItemId = itemDescriptors[i].ItemId, Value = valueResults[i].Value?.ToString() }); GridView1.DataSource = data; GridView1.DataBind(); } } }
' DataGridWebApplication: Demonstrates how easily can GridView be populated with data read from OPC Data Access server. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.BaseLib.OperationModel Imports OpcLabs.EasyOpc.DataAccess.Extensions ' ReSharper disable InconsistentNaming Partial Public Class _Default Inherits UI.Page Private Class Row Public Property ItemId As String Public Property Value As String End Class Shared Sub New() ' Enable auto-subscribing optimization (not necessary), which can improve performance with repeated Read requests. Client.TryEnableAutoSubscribingOptimization() End Sub ' Use a shared client instance to allow for better optimization. Shared ReadOnly Client As New EasyDAClient Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim itemDescriptors = New DAItemDescriptor() {"Simulation.Register_BOOL", "Simulation.Register_I2", "Demo.Ramp", "Demo.Single"} Dim valueResults() As ValueResult = Client.ReadMultipleItemValues("OPCLabs.KitServer.2", itemDescriptors) Dim data = New List(Of Row)() For i As Integer = 0 To itemDescriptors.Length - 1 data.Add(New Row With {.ItemId = itemDescriptors(i).ItemId, .Value = valueResults(i).Value.ToString()}) Next i GridView1.DataSource = data GridView1.DataBind() End Sub End Class
Copyright © 2004-2024 CODE Consulting and Development, s.r.o., Plzen. All rights reserved.
Send Documentation Feedback. Technical Support